package cn.m3a1.service.master;

import cn.m3a1.bean.*;
import cn.m3a1.dao.AbsentNoteMapper;
import cn.m3a1.dao.TclassMapper;
import cn.m3a1.dao.UserMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author wyj
 * @date 2019/7/10
 * @time 上午10:45
 */
@Service
public class MasterMyclassService {
    @Autowired
    TclassMapper tclassMapper;
    @Autowired
    UserMapper userMapper;
    @Autowired
    AbsentNoteMapper absentNoteMapper;
    /**
     * 查询该班主任所教的班级
     * @param id
     * @return
     */
    public List<Tclass> getAllClass(int id){
        TclassExample tclassExample=new TclassExample();
        TclassExample.Criteria criteria = tclassExample.createCriteria();
        criteria.andManageridEqualTo(id);
        List<Tclass> tclasses = tclassMapper.selectByExample(tclassExample);
       return  tclasses;
    }

    /**
     * 根据班级id查询班级学生信息
     * @param id
     * @return
     */
    public List<User> getUserByTclass(int id){
        List<User> users = userMapper.selectByExamplewithstu(id);
        return  users;
    }

    /**
     * 根据班主任的id获取所要审批的信息
     * @return
     */
   public  List<AbsentNote>  getByMaster(int id){
       List<AbsentNote> absentNotes = absentNoteMapper.selectByExampleWithUser(id);
       return  absentNotes;
   }

   public  boolean setApproval(AbsentNote absentNote){
       AbsentNoteExample absentNoteExample=new AbsentNoteExample();
       AbsentNoteExample.Criteria criteria = absentNoteExample.createCriteria();
       criteria.andIdEqualTo(absentNote.getId());
       criteria.andManageridEqualTo(absentNote.getManagerid());
       int i = absentNoteMapper.updateByExampleSelective(absentNote, absentNoteExample);
       return  i==1;
   }

    /**
     * 根据假单id获取假单信息
     * @param id
     * @return
     */
   public  AbsentNote getAbsentNote(int id){
       AbsentNoteExample absentNoteExample=new AbsentNoteExample();
       AbsentNoteExample.Criteria criteria = absentNoteExample.createCriteria();
       criteria.andIdEqualTo(id);
       List<AbsentNote> absentNotes = absentNoteMapper.selectByExample(absentNoteExample);
       return  absentNotes.get(0);
   }
}
